<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        #imglist img{
            width: 300px;
            height: 200px;
        }
    </style>
</head>
<body>
    <h1>JS onerror</h1>
    <hr>

     <div id="imglist">
         <img src="./imgs/mm001.jpg">
         <img src="./imgs/mm002.jpg">
         <img src="./imgs/mm003.jpg">
         <img src="./imgs/mm004.jpg">
         <img src="./imgs/mm004444.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm005.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm006.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm007.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm008.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm009.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm010.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm011.jpg">
         <img src="./imgs/mm012.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm00444342434.jpg">
         <img src="./imgs/mm013.jpg">
         <img src="./imgs/mm014.jpg">
         <img src="./imgs/mm015.jpg">
     </div>

    <script>
        var imgs = imglist.getElementsByTagName('img');

        for (var i = 0; i < imgs.length; i++) {
            imgs[i].onerror = function(){
                this.src = './imgs/error.jpg';
            }
        }

    </script>
</body>
</html>